import { UploadCountTopBottom, CountTopBottom } from '../../../../services/monitor_options_service';

export default {
  namespace: 'aiwatch',
  state: {
    data: {
      list: [],
      pagination: {},
    },
    data2: {
      list: {},
      pagination: {},
    },
    filterData: {
      list: [],
    },
  },

  effects: {
    *UploadCountTopBottom({ payload, callback }, { call, put }) {
      const response = yield call(UploadCountTopBottom, payload);
      if (typeof response === 'undefined') {
        return;
      }
      yield put({
        type: 'savew',
        payload: response,
      });
      if (callback) {
        callback(response);
      }
    },

    *CountTopBottom({ payload, callback }, { call, put }) {
      const response = yield call(CountTopBottom, payload);
      if (typeof response === 'undefined') {
        return;
      }
      yield put({
        type: 'savew',
        payload: response,
      });
      if (callback) {
        callback(response);
      }
    },
  },

  reducers: {
    savew(state, action) {
      return {
        ...state,
        data: action.payload,
      };
    },
    saveA(state, action) {
      return {
        ...state,
        data2: action.payload,
      };
    },
    saveFilter(state, action) {
      return {
        ...state,
        filterData: action.payload,
      };
    },
  },
};
